package cn.xspace.wnx.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

import cn.xspace.wnx.R;
import cn.xspace.wnx.entity.WNXBean;
import com.xspace.android.xafcommon.util.HeadShowUtil;

/**
 * Created by Administrator on 2016/11/12.
 */

public class WnxOrgListAdapter extends BaseAdapter {


    private static final String TAG = "WnxOrgListAdapter";
    private ArrayList<WNXBean> dataList = new ArrayList<>();
    LayoutInflater mInflater;

    private static Context mContext;

    public WnxOrgListAdapter(Context context, ArrayList<WNXBean> dataList) {
        this.dataList = dataList;
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public WNXBean getItem(int i) {
        return dataList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return dataList.get(i).hashCode();
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        WNXBean wnxBean = getItem(i);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.listitem_group, null);
            viewHolder = new ViewHolder();
            viewHolder.findView(convertView);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.setData(wnxBean);
        return convertView;
    }


    static class ViewHolder {
        ImageView headImg;
        TextView nameTxt;

        public void findView(View view) {
            this.headImg = (ImageView) view.findViewById(R.id.img_head);
            this.nameTxt = (TextView) view.findViewById(R.id.txt_name);
            view.setTag(this);
        }

        public void setData(WNXBean entity) {
            HeadShowUtil.headShow(mContext, entity.msg_logo, "", this.headImg, HeadShowUtil.HeadType.OrgLogo);
            this.nameTxt.setText(entity.msg_sender_name);
        }
    }
}
